//
//  ViewController.m
//  test1
//
//  Created by anan on 2018/8/23.
//  Copyright © 2018年 Plan. All rights reserved.
//

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property (nonatomic,strong) AVSpeechSynthesizer * synthesizer;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
}





-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSString *voiceString =  [NSString stringWithFormat:@"收款%@元！", @"1000000"];
    //  语音合成
    [self syntheticVoice:voiceString];
}

- (void)syntheticVoice:(NSString *)string {
    
    //  语音合成
    self.synthesizer = [[AVSpeechSynthesizer alloc] init];
    AVSpeechUtterance *speechUtterance = [AVSpeechUtterance speechUtteranceWithString:string];
    //设置语言类别（不能被识别，返回值为nil）
    speechUtterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
    //设置语速快慢
    speechUtterance.rate = 0.55;
    
    //语音合成器会生成音频
    [self.synthesizer speakUtterance:speechUtterance];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
